package com.wzdigit.wms.wms.controller.inv;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.request.inv.InvInfoRequest;
import com.wzdigit.wms.basic.client.response.inv.report.InvInfoDtlResponse;
import com.wzdigit.wms.basic.client.response.inv.report.InvInfoMainResponse;
import com.wzdigit.wms.basic.client.response.inv.report.InvInfoSnResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.inv.InvInfoReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存查询PDA控制层
 * Created by zyf on 2021/7/12 12:01
 */
@RestController
@Api(tags = "库存查询")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class InvInfoReportController {
    public static final String REQUEST_MODEL = "/invSearch";

    @Autowired
    private InvInfoReportService invInfoReportService;

    @ApiOperation(value = "【库存查询】主页",notes = "【库存查询】主页")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/searchQualifiedGoods")
    public PagerInfo<List<InvInfoMainResponse>> searchInvMain(
            String goodsSn, String poNo,
            String locCode, Boolean flag, Pager<?> pager,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return invInfoReportService.searchMain(goodsSn,poNo,locCode,flag, pager);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "【库存查询】库存详情",notes = "【库存查询】库存详情")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/invDtl")
    public InvInfoDtlResponse searchInvDtl(
            InvInfoRequest request,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return invInfoReportService.searchInvDtl(request);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "【库存查询】条码明细",notes = "【库存查询】条码明细")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/invGoods")
    public List<InvInfoSnResponse> searchInvGoodsList(
            InvInfoRequest request,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return invInfoReportService.searchInvSnList(request);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

}
